package com.mk.web;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.mk.web.model.Flower;

/**
 * Created by WangChen on 2018/11/26 21:44.
 */
public class MybatisMain {

    public static void main(String [] args) {
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream("mybatis.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = factory.openSession();

//        List<Flower> flowerList = sqlSession.selectList("a.b.c.selectByName", "花2");
//        for (Flower flower : flowerList){
//            System.out.println(flower);
//        }

        Map<String, Object> map = new HashMap<>(2);
        map.put("name", "花2");
        map.put("price", 6.3);
        List<Flower> flowerList2 = sqlSession.selectList("a.b.c.selectByNameAndPrice", map);
        for (Flower flower : flowerList2){
            System.out.println(flower);
        }

        sqlSession.close();


    }
}
